package com.sanbi.erp.core.system;

import com.github.houbb.property.bs.PropertyBs;
import com.sanbi.erp.core.config.ErrorCodeConfig;

/**
 * @author wanggang
 * @desc 系统错误编码
 * @time 2022/8/9 17:41
 */
public class ErrorEnum {
    // 参数不对
    private static final Integer badReqArgumentCode;
    private static final String badReqArgumentMessage;
    //系统内部异常
    private static final Integer SERIOUS_CODE;
    private static final String SERIOUS_MESSAGE;

    // 50065 IO操作_新增失败
    private static final Integer INSERT_UNSUCCESSFUL_CODE;
    private static final String INSERT_UNSUCCESSFUL_MESSAGE;
    // 50066 IO操作_删除失败
    private static final Integer DELETE_UNSUCCESSFUL_CODE;
    private static final String DELETE_UNSUCCESSFUL_MESSAGE;
    // 50067 IO操作_修改失败
    private static final Integer UPDATE_UNSUCCESSFUL_CODE;
    private static final String UPDATE_UNSUCCESSFUL_MESSAGE;
    // 50068 IO操作_查询失败
    private static final Integer SELECT_UNSUCCESSFUL_CODE;
    private static final String SELECT_UNSUCCESSFUL_MESSAGE;

    // 50061 验证码未过期，5分钟内不能重复发送
    private static final Integer codeNotOverTimeCode;
    private static final String codeNotOverTimeMessage;
    // 50062 验证码输入错误
    private static final Integer emailVerificationCodeWrongCode;
    private static final String emailVerificationCodeWrongMessage;
    // 50063 新密码与原密码不能一致
    private static final Integer newPasswordOldNotFitCode;
    private static final String newPasswordOldNotFitMessage;
    // 50064 昵称已经注册
    private static final Integer nickNameRegisteredCode;
    private static final String nickNameRegisteredMessage;
    // 账户已存在不能重复注册
    private static final Integer userEmailPasswordIsExistCode;
    private static final String userEmailPasswordIsExistMessage;

    // sku不正确
    private static final Integer authInvalidPasswordCode;
    private static final String authInvalidPasswordMessage;
    // sku不存在
    private static final Integer skuNotCode;
    private static final String skuNotMessage;
    // 类目被商品使用无法删除
    private static final Integer categoryNotDeleteCode;
    private static final String categoryNotDeleteMessage;
    // 类目名称重复
    private static final Integer categoryNameRepetitionCode;
    private static final String categoryNameRepetitionMessage;

    static {
        ErrorCodeConfig config = new ErrorCodeConfig();
        PropertyBs.getInstance("error-code.properties").asBean(config);
        //40001 请求参数错误
        badReqArgumentCode = config.getBadReqArgumentCode();
        badReqArgumentMessage = config.getBadReqArgumentMsg();
        //502系统内部异常
        SERIOUS_CODE = config.getSeriousCode();
        SERIOUS_MESSAGE = config.getSeriousMessage();

        // CRUD 通用错误信息捕获 50065-50068
        INSERT_UNSUCCESSFUL_CODE = config.getInsertUnsuccessfulCode();
        INSERT_UNSUCCESSFUL_MESSAGE = config.getInsertUnsuccessfulMessage();
        DELETE_UNSUCCESSFUL_CODE = config.getDeleteUnsuccessfulCode();
        DELETE_UNSUCCESSFUL_MESSAGE = config.getDeleteUnsuccessfulMessage();
        UPDATE_UNSUCCESSFUL_CODE = config.getUpdateUnsuccessfulCode();
        UPDATE_UNSUCCESSFUL_MESSAGE = config.getUpdateUnsuccessfulMessage();
        SELECT_UNSUCCESSFUL_CODE = config.getSelectUnsuccessfulCode();
        SELECT_UNSUCCESSFUL_MESSAGE = config.getSelectUnsuccessfulMessage();

        // 50061 验证码未过期，5分钟内不能重复发送
        codeNotOverTimeCode = config.getCodeNotOverTimeCode();
        codeNotOverTimeMessage = config.getCodeNotOverTimeMessage();
        // 50062 验证码输入错误
        emailVerificationCodeWrongCode = config.getEmailVerificationCodeWrongCode();
        emailVerificationCodeWrongMessage = config.getEmailVerificationCodeWrongMessage();
        // 50063 新密码与原密码不能一致
        newPasswordOldNotFitCode = config.getNewPasswordOldNotFitCode();
        newPasswordOldNotFitMessage = config.getNewPasswordOldNotFitMessage();
        // 50064 昵称已经注册
        nickNameRegisteredCode = config.getNickNameRegisteredCode();
        nickNameRegisteredMessage = config.getNickNameRegisteredMessage();
        // 账户已存在不能重复注册
        userEmailPasswordIsExistCode = config.getUserEmailPasswordIsExistCode();
        userEmailPasswordIsExistMessage = config.getUserEmailPasswordIsExistMessage();

        // sku不正确
        authInvalidPasswordCode = config.getAuthInvalidPasswordCode();
        authInvalidPasswordMessage = config.getAuthInvalidPasswordMessage();
        // sku不正确
        skuNotCode = config.getSkuNotCode();
        skuNotMessage = config.getSkuNotMessage();
        // 类目被商品使用无法删除
        categoryNotDeleteCode = config.getCategoryNotDeleteCode();
        categoryNotDeleteMessage = config.getCategoryNotDeleteMessage();
        // 类目名称重复
        categoryNameRepetitionCode = config.getCategoryNameRepetitionCode();
        categoryNameRepetitionMessage = config.getCategoryNameRepetitionMessage();
    }

    public enum ErrorCode {
        //40001 请求参数错误
        BadReqArgument(badReqArgumentCode, badReqArgumentMessage),
        //系统内部异常
        Serious(SERIOUS_CODE, SERIOUS_MESSAGE),
        // 50061 验证码未过期，10分钟内不能重复发送
        CodeNotOverTime(codeNotOverTimeCode, codeNotOverTimeMessage),
        // 50062 验证码输入错误
        EmailVerificationCodeWrong(emailVerificationCodeWrongCode, emailVerificationCodeWrongMessage),
        // 50063 新密码与原密码不能一致
        NewPasswordOldNotFit(newPasswordOldNotFitCode, newPasswordOldNotFitMessage),
        // 50064 昵称已经注册
        NickNameRegistered(nickNameRegisteredCode, nickNameRegisteredMessage),
        // 账户已存在不能重复注册
        userEmailPasswordIsExist(userEmailPasswordIsExistCode, userEmailPasswordIsExistMessage),
        // CRUD 通用错误信息捕获 50065-50068
        InsertUnsuccessful(INSERT_UNSUCCESSFUL_CODE, INSERT_UNSUCCESSFUL_MESSAGE),
        DeleteUnsuccessful(DELETE_UNSUCCESSFUL_CODE, DELETE_UNSUCCESSFUL_MESSAGE),
        UpdateUnsuccessful(UPDATE_UNSUCCESSFUL_CODE, UPDATE_UNSUCCESSFUL_MESSAGE),
        SelectUnsuccessful(SELECT_UNSUCCESSFUL_CODE, SELECT_UNSUCCESSFUL_MESSAGE),

        // SKU不正确
        authInvalidPassword(authInvalidPasswordCode, authInvalidPasswordMessage),
        // SKU不存在
        skuNot(skuNotCode, skuNotMessage),
        // 类目被商品使用无法删除
        categoryNotDelete(categoryNotDeleteCode, categoryNotDeleteMessage),
        // 类目名称重复
        categoryNameRepetition(categoryNameRepetitionCode, categoryNameRepetitionMessage),

        ;

        private final Integer code;
        private final String message;

        ErrorCode(Integer code, String message) {
            this.code = code;
            this.message = message;
        }

        public Integer getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }
    }

}
